package com.nullpointer.xchat.adapter;

import android.app.Activity;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.nullpointer.xchat.R;
import com.nullpointer.xchat.utils.Common;

public class ImageSlideAdapter extends PagerAdapter {
	private Context context;

	public ImageSlideAdapter(Context context) {
		super();
		this.context = context;
	}

	@Override
	public int getCount() {
		return Common.tipImageResources.length;
	}

	@Override
	public View instantiateItem(ViewGroup container, final int position) {
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(R.layout.item_vp_image, container, false);

		ImageView mImageView = (ImageView) view.findViewById(R.id.iv_image);
		mImageView.setImageResource(Common.tipImageResources[position]);
		container.addView(view);
		return view;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		container.removeView((View) object);
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		return view == object;
	}
}